# !/usr/bin/env python3
# -*- coding: utf-8 -*-

from wtforms.validators import ValidationError
import re

__author__ = 'InG_byr'


class MacAddressValidator(object):
    def __init__(self, message=None):
        self.message = message

    def __call__(self, form, field):
        pattern = re.compile(r'''
                      (^([0-9A-F]{1,2}[-]){5}([0-9A-F]{1,2})$
                      |^([0-9A-F]{1,2}[:]){5}([0-9A-F]{1,2})$
                      |^([0-9A-F]{1,2}[.]){5}([0-9A-F]{1,2})$)
                      ''', re.VERBOSE | re.IGNORECASE)
        check = re.match(pattern, field.data)
        if not check:
            raise ValidationError(self.message)
